<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.ArrayList"%>
<%@page import="utils.Article" %>
<%@page import="main.MainRunner" %>
<%@page import="java.util.Calendar" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title>Results Page</title>
</head>
<body>
		<%
			boolean excp=false;
			ArrayList<Article> arrls=(ArrayList<Article>)session.getAttribute("ArticelsArr");
			String ticker=(String)session.getAttribute("ticker");
			String oldTicker=request.getParameter("oldTicker");
			try{
				if (arrls==null ||!ticker.equalsIgnoreCase(oldTicker)){
					arrls= MainRunner.invokeRun(ticker);	
					session.setAttribute("ArticelsArr",arrls);		
				}	
			}
			catch(Exception e){
				excp=true;
			}		
				 %>
				 
		<%
			if (!excp){  %>
						
		<h1>The results for <%=session.getAttribute("ticker") %>,<%=arrls.get(0).getCompany() %> are:</h1>
		<h2>Overall Grade: <%=arrls.get(0).getOverallGrade() %></h2>
		<table style="border-color:blue; text-align: center">
			<tr style="width: 677px">
				<td style="width: 45px"><b>Grade</b></td>
				<td style="width: 325px"><b>Header</b></td>
				<td style="width: 79px"><b>Date</b></td>
				<td style="width: 148px"><b>URL</b></td>
				<td style="width: 148px"><b>Tagged Text</b></td>
			</tr>
			
				<%
				Article artcl=null;
				for (int i=0;i<arrls.size();i++){
					artcl=arrls.get(i);
					if (artcl.getGrade()!=-2.0){
				%>
			<tr>
				<td style="width: 45px;text-align: left"><%=artcl.getGrade() %></td>
				<td style="width: 325px;text-align: left"><%=artcl.getHeader() %></td>
				<td style="width: 79px;text-align: left"><%=artcl.getDate().get(Calendar.DAY_OF_MONTH)%>/<%=artcl.getDate().get(Calendar.MONTH)+1%>/<%=artcl.getDate().get(Calendar.YEAR) %></td>
				<td style="width: 148px;text-align: left"><a href="<%=artcl.getUrl()%>">Read the original article</a></td>
				<td style="width: 148px;text-align: left"><a href="/tm/TaggedTextViewer.jsp?Article=<%= i %>">Read the tagged article</a></td>
			</tr>
				<%
					}
				}
				
				 %>
			
		</table>
		<%}
		  else{ %>
		  <h1>The service is temporary unavailable. Please try later.</h1>
		  <%} %>
</body>
</html>